﻿using System.ComponentModel;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using Dictionary.ERP;
using Common.Class;
using System.Windows.Forms;
using Common;
using System.Drawing;

namespace Dictionary
{
    public class xfmRankAdd : XtraForm
    {
        public delegate void AddedEventHander(object sender, DIC_SALARY_RANK Item);

        public delegate void UpdatedEventHander(object sender, DIC_SALARY_RANK Item);

        private readonly IContainer components;
        public Common.Class.RowClickEventArgs m_RowClickEventArgs;
        private xucRankAdd ucAdd;

        public xfmRankAdd()
        {
            components = null;
            InitializeComponent();
        }

        public xfmRankAdd(Actions Action)
        {
            components = null;
            InitializeComponent();
            Init();
            ucAdd.Status = Action;
            ucAdd.SetData(new DIC_SALARY_RANK().NewID());
            Text = ((SysOption.Language == "EN") ? "New " : "Th\x00eam ") + Text;
        }

        public xfmRankAdd(Actions Action, DIC_SALARY_RANK Item)
        {
            components = null;
            InitializeComponent();
            Init();
            ucAdd.Status = Action;
            if (Action == Actions.Update)
            {
                ucAdd.SetData(Item);
                Text = ((SysOption.Language == "EN") ? "Edit " : "Cập Nhật ") + Text;
            }
            else if (Action == Actions.Delete)
            {
                ucAdd.SetData(Item.RankCode);
            }
        }

        public event AddedEventHander Added;

        public event UpdatedEventHander Updated;

        public void Delete()
        {
            ucAdd.Delete();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Init()
        {
            ucAdd.CancelClick += new ButtonClickEventHander(ucAdd_CancelClick);
            ucAdd.Success += ucAdd_Success;
            Text = (SysOption.Language == "EN") ? "DIC_SALARY_RANK" : Text;
        }

        private void InitializeComponent()
        {
            var button = new MenuButton();
            var command = new ItemCommand();
            var command2 = new ItemCommand();
            var command3 = new ItemCommand();
            var command4 = new ItemCommand();
            var command5 = new ItemCommand();
            var command6 = new ItemCommand();
            var command7 = new ItemCommand();
            var command8 = new ItemCommand();
            var command9 = new ItemCommand();
            var command10 = new ItemCommand();
            var command11 = new ItemCommand();
            var command12 = new ItemCommand();
            var command13 = new ItemCommand();
            var command14 = new ItemCommand();
            var command15 = new ItemCommand();
            var command16 = new ItemCommand();
            var command17 = new ItemCommand();
            var command18 = new ItemCommand();
            var command19 = new ItemCommand();
            var command20 = new ItemCommand();
            var command21 = new ItemCommand();
            var command22 = new ItemCommand();
            var command23 = new ItemCommand();
            var command24 = new ItemCommand();
            var command25 = new ItemCommand();
            var command26 = new ItemCommand();
            var command27 = new ItemCommand();
            var command28 = new ItemCommand();
            var command29 = new ItemCommand();
            ucAdd = new xucRankAdd();
            base.SuspendLayout();
            ucAdd.Dock = DockStyle.Fill;
            ucAdd.IsClose = CloseOrNew.None;
            ucAdd.Location = new Point(0, 0);
            ucAdd.Name = "ucAdd";
            ucAdd.NotSave = false;
            command.Caption = "";
            command.Enable = false;
            command.Visibility = BarItemVisibility.Never;
            button.Add = command;
            command2.Caption = "";
            command2.Enable = false;
            command2.Visibility = BarItemVisibility.Never;
            button.Cancel = command2;
            command3.Caption = "";
            command3.Enable = false;
            command3.Visibility = BarItemVisibility.Never;
            button.Change = command3;
            command4.Caption = "";
            command4.Enable = false;
            command4.Visibility = BarItemVisibility.Never;
            button.Close = command4;
            command5.Caption = "";
            command5.Enable = false;
            command5.Visibility = BarItemVisibility.Never;
            button.Custom = command5;
            command6.Caption = "";
            command6.Enable = false;
            command6.Visibility = BarItemVisibility.Never;
            button.Delete = command6;
            command7.Caption = "";
            command7.Enable = false;
            command7.Visibility = BarItemVisibility.Never;
            button.Export = command7;
            command8.Caption = "";
            command8.Enable = false;
            command8.Visibility = BarItemVisibility.Never;
            button.Filter = command8;
            command9.Caption = "";
            command9.Enable = false;
            command9.Visibility = BarItemVisibility.Never;
            button.FilterCustomer = command9;
            command10.Caption = "";
            command10.Enable = false;
            command10.Visibility = BarItemVisibility.Never;
            button.FilterStock = command10;
            command11.Caption = "";
            command11.Enable = false;
            command11.Visibility = BarItemVisibility.Never;
            button.Find = command11;
            button.GClose = false;
            button.GCommand = false;
            button.GExport = false;
            command12.Caption = "";
            command12.Enable = false;
            command12.Visibility = BarItemVisibility.Never;
            button.Go = command12;
            button.GOption = false;
            button.GPrint = false;
            button.GRecords = false;
            button.GSearchBar = false;
            button.GSettings = false;
            button.GVaildation = false;
            command13.Caption = "";
            command13.Enable = false;
            command13.Visibility = BarItemVisibility.Never;
            button.Import = command13;
            command14.Caption = "";
            command14.Enable = false;
            command14.Visibility = BarItemVisibility.Never;
            button.Next = command14;
            command15.Caption = "";
            command15.Enable = false;
            command15.Visibility = BarItemVisibility.Never;
            button.PageSetup = command15;
            button.PHome = false;
            command16.Caption = "";
            command16.Enable = false;
            command16.Visibility = BarItemVisibility.Never;
            button.Previous = command16;
            command17.Caption = "";
            command17.Enable = false;
            command17.Visibility = BarItemVisibility.Never;
            button.Print = command17;
            command18.Caption = "";
            command18.Enable = false;
            command18.Visibility = BarItemVisibility.Never;
            button.PrintPreview = command18;
            button.PTool = false;
            command19.Caption = "";
            command19.Enable = false;
            command19.Visibility = BarItemVisibility.Never;
            button.Redo = command19;
            command20.Caption = "";
            command20.Enable = false;
            command20.Visibility = BarItemVisibility.Never;
            button.Refresh = command20;
            command21.Caption = "";
            command21.Enable = false;
            command21.Visibility = BarItemVisibility.Never;
            button.Save = command21;
            command22.Caption = "";
            command22.Enable = false;
            command22.Visibility = BarItemVisibility.Never;
            button.SaveAndClose = command22;
            command23.Caption = "";
            command23.Enable = false;
            command23.Visibility = BarItemVisibility.Never;
            button.SaveAndNew = command23;
            command24.Caption = "";
            command24.Enable = false;
            command24.Visibility = BarItemVisibility.Never;
            button.Search = command24;
            command25.Caption = "";
            command25.Enable = false;
            command25.Visibility = BarItemVisibility.Never;
            button.SearchText = command25;
            command26.Caption = "";
            command26.Enable = false;
            command26.Visibility = BarItemVisibility.Never;
            button.Task = command26;
            command27.Caption = "";
            command27.Enable = false;
            command27.Visibility = BarItemVisibility.Never;
            button.Undo = command27;
            command28.Caption = "";
            command28.Enable = false;
            command28.Visibility = BarItemVisibility.Never;
            button.Vaildate = command28;
            command29.Caption = "";
            command29.Enable = false;
            command29.Visibility = BarItemVisibility.Never;
            button.View = command29;
            ucAdd.RibbonBar = button;
            ucAdd.Size = new Size(0x14b, 0xa8);
            ucAdd.Status = Actions.Add;
            ucAdd.TabIndex = 0;
            ucAdd.Title = "";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x14d, 0xb0);
            base.Controls.Add(ucAdd);
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmRankAdd";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.StartPosition = FormStartPosition.CenterScreen;
            Text = "Ngạch Lương";
            base.ResumeLayout(false);
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Escape:
                    base.Close();
                    return true;

                case Keys.F2:
                    ucAdd.IsClose = CloseOrNew.Close;
                    ucAdd.Save();
                    return true;

                case (Keys.Control | Keys.S):
                    ucAdd.IsClose = CloseOrNew.Close;
                    ucAdd.Save();
                    return true;

                case (Keys.Control | Keys.W):
                    ucAdd.IsClose = CloseOrNew.Close;
                    ucAdd.Save();
                    return true;

                case (Keys.Control | Keys.Shift | Keys.S):
                    ucAdd.IsClose = CloseOrNew.New;
                    ucAdd.Save();
                    return true;

                case (Keys.Alt | Keys.D):
                    return true;

                case (Keys.Alt | Keys.X):
                    base.Close();
                    return true;
            }
            return false;
        }

        public void RaiseAddedEventHander(DIC_SALARY_RANK Item)
        {
            if (Added != null)
            {
                Added(this, Item);
            }
        }

        public void RaiseUpdatedEventHander(DIC_SALARY_RANK Item)
        {
            if (Updated != null)
            {
                Updated(this, Item);
            }
        }

        private void ucAdd_CancelClick(object sender)
        {
            base.Close();
        }

        private void ucAdd_Success(object sender, DIC_SALARY_RANK Item)
        {
            if (ucAdd.Status == Actions.Add)
            {
                RaiseAddedEventHander(Item);
            }
            else if (ucAdd.Status == Actions.Update)
            {
                RaiseUpdatedEventHander(Item);
            }
            if (ucAdd.IsClose == CloseOrNew.Close)
            {
                base.Close();
            }
            ucAdd.Clear();
        }
    }
}